//
//  UIButton+SYImageLocation.m
//  Hyukoh
//
//  Created by HuiMin on 2017/9/19.
//  Copyright © 2017年 Lsy. All rights reserved.
//

#import "UIButton+SYImageLocation.h"

@implementation UIButton (SYImageLocation)
- (void)SY_buttonLocation:(buttonImageLocation)location space:(CGFloat )space{
    if (location == imageLeft) {
        self.imageEdgeInsets = UIEdgeInsetsMake(0, -0.5*space, 0, 0.5*space);
        self.titleEdgeInsets = UIEdgeInsetsMake(0, 0.5 *space, 0, -0.5*space);
    }else if (location == imageRight){
        CGFloat imageW = self.imageView.image.size.width;
        CGFloat titleW = self.titleLabel.frame.size.width;
        CGFloat imageOffset = space*0.5 +imageW;
        CGFloat titleOffset = space*0.5 + titleW;
        
        self.imageEdgeInsets = UIEdgeInsetsMake(0, imageOffset, 0, -imageOffset);
        self.titleEdgeInsets = UIEdgeInsetsMake(0, -titleOffset, 0,titleOffset);
    }else if (location == imageTop){
        CGFloat imageW = self.imageView.image.size.width;
        CGFloat imageH = self.imageView.image.size.height;
        CGFloat titleW = self.titleLabel.intrinsicContentSize.width;
        CGFloat titleH = self.titleLabel.intrinsicContentSize.height;
        
        
        self.imageEdgeInsets = UIEdgeInsetsMake(-titleH-space,0, 0,-titleW);
        self.titleEdgeInsets = UIEdgeInsetsMake(0,-imageW,-imageH-space,0);
    }else if (location == imageBottom){
        CGFloat imageW = self.imageView.image.size.width;
        CGFloat imageH = self.imageView.image.size.height;
        CGFloat titleW = self.titleLabel.intrinsicContentSize.width;
        CGFloat titleH = self.titleLabel.intrinsicContentSize.height;
        
        self.imageEdgeInsets = UIEdgeInsetsMake(titleH+space,0, 0,-titleW);
        self.titleEdgeInsets = UIEdgeInsetsMake(0,-imageW, imageH+space,0);
    }
}
@end
